package com.dzm.portal.controller;

import com.dzm.portal.service.PortalService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.domain.Content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 作者：Dzm
 * 时间：2024-09-07-11:46
 * 功能：
 */

@Controller
@RequestMapping
public class PortalController {

    @Autowired
    private PortalService portalService;

    @GetMapping({"/", "/index.html"})
    public String index(Model model) {
        //1.1 根据广告分类id查找广告列表
        List<Content> contentList = portalService.getContentsByCateId(2L);

        model.addAttribute("contentList", contentList);
        return "index";
    }

    @GetMapping("/{id}")
    @ResponseBody
    public AjaxResult getById(@PathVariable("id") Long id) {
        Content content = portalService.getContentById(id);

        return AjaxResult.success(content);
    }
}
